package cn.iocoder.yudao.module.biz.controller.admin.licenceAnalyzeData;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.licenceAnalyzeData.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.licenceAnalyzeData.BizLicenceAnalyzeDataDO;
import cn.iocoder.yudao.module.biz.convert.licenceAnalyzeData.BizLicenceAnalyzeDataConvert;
import cn.iocoder.yudao.module.biz.service.licenceAnalyzeData.BizLicenceAnalyzeDataService;

@Api(tags = "管理后台 - 危险作业票分析数据")
@RestController
@RequestMapping("/biz/licence-analyze-data")
@Validated
public class BizLicenceAnalyzeDataController {

    @Resource
    private BizLicenceAnalyzeDataService licenceAnalyzeDataService;

    @PostMapping("/create")
    @ApiOperation("创建危险作业票分析数据")
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:create')")
    public CommonResult<String> createLicenceAnalyzeData(@Valid @RequestBody BizLicenceAnalyzeDataCreateReqVO createReqVO) {
        return success(licenceAnalyzeDataService.createLicenceAnalyzeData(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新危险作业票分析数据")
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:update')")
    public CommonResult<Boolean> updateLicenceAnalyzeData(@Valid @RequestBody BizLicenceAnalyzeDataUpdateReqVO updateReqVO) {
        licenceAnalyzeDataService.updateLicenceAnalyzeData(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除危险作业票分析数据")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:delete')")
    public CommonResult<Boolean> deleteLicenceAnalyzeData(@RequestParam("id") String id) {
        licenceAnalyzeDataService.deleteLicenceAnalyzeData(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得危险作业票分析数据")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:query')")
    public CommonResult<BizLicenceAnalyzeDataRespVO> getLicenceAnalyzeData(@RequestParam("id") String id) {
        BizLicenceAnalyzeDataDO licenceAnalyzeData = licenceAnalyzeDataService.getLicenceAnalyzeData(id);
        return success(BizLicenceAnalyzeDataConvert.INSTANCE.convert(licenceAnalyzeData));
    }

    @GetMapping("/list")
    @ApiOperation("获得危险作业票分析数据列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:query')")
    public CommonResult<List<BizLicenceAnalyzeDataRespVO>> getLicenceAnalyzeDataList(@RequestParam("ids") Collection<String> ids) {
        List<BizLicenceAnalyzeDataDO> list = licenceAnalyzeDataService.getLicenceAnalyzeDataList(ids);
        return success(BizLicenceAnalyzeDataConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得危险作业票分析数据分页")
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:query')")
    public CommonResult<PageResult<BizLicenceAnalyzeDataRespVO>> getLicenceAnalyzeDataPage(@Valid BizLicenceAnalyzeDataPageReqVO pageVO) {
        PageResult<BizLicenceAnalyzeDataDO> pageResult = licenceAnalyzeDataService.getLicenceAnalyzeDataPage(pageVO);
        return success(BizLicenceAnalyzeDataConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出危险作业票分析数据 Excel")
    @PreAuthorize("@ss.hasPermission('biz:licence-analyze-data:export')")
    @OperateLog(type = EXPORT)
    public void exportLicenceAnalyzeDataExcel(@Valid BizLicenceAnalyzeDataExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizLicenceAnalyzeDataDO> list = licenceAnalyzeDataService.getLicenceAnalyzeDataList(exportReqVO);
        // 导出 Excel
        List<BizLicenceAnalyzeDataExcelVO> datas = BizLicenceAnalyzeDataConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "危险作业票分析数据.xls", "数据", BizLicenceAnalyzeDataExcelVO.class, datas);
    }

}
